<?php
/**
 * @Notes: 文件描述
 * @Interface getCondition
 * @Return mixed
 * @Author: fc
 * @Time: 2021/9/22 20:34
 */

namespace app\common\model;


use think\Model;
use think\Facade\Cache;
use think\Facade\Log;

class Order extends Model
{
    //protected $observerClass = 'app\common\event\OrderGoods';

    //public static function init()
    //{
    //    //self::observe(\app\common\event\OrderGoods::class);
    //
    //    //self::event('before_write', function ($order) {
    //    //    $order['sn'] = 'FC'.mt_rand(1000,9999).time();
    //    //});
    //    //
    //    //self::event('after_write', function($order) {
    //    //    Log::info('hello fc everybody jump');
    //    //
    //    //    $updateData['order_state'] = 50;
    //    //    $updateData['update_time'] = time();
    //    //    OrderGoods::where('order_id', 365)->update($updateData);
    //    //});
    //
    //    self::event('after_update', function ($data) {
    //        Log::info('hello fc everybody jump20222222');
    //        var_dump('更新成功后');
    //    });
    //
    //}

    protected static function init()
    {
        self::observe(\app\common\event\OrderGoods::class);

        //self::beforeUpdate(function ($order) {
        //    if ($order->id != 365) {
        //        return false;
        //    }
        //});
        //
        //self::afterUpdate(function ($order) {
        //    $updateData['order_state'] = $order->order_state;
        //    $updateData['update_time'] = time();
        //    OrderGoods::where('order_id', $order->id)->update($updateData);
        //});

        //self::beforeWrite(function($data) {
        //    $data['sn'] = 'BQS'.time().mt_rand(100,99999999);
        //});
        //
        //self::afterWrite(function($data) {
        //    $newData['order_id'] = $data->id;
        //    $newData['children_sn'] = 'Fc'.time().mt_rand(1,99999);
        //    (new OrderGoods())->save($newData);
        //});

        //self::beforeWrite(function ($data) {
        //    $data['sn'] = 'F'.time().mt_rand(100,99999);
        //});

        //self::afterWrite(function ($data) {
        //    $newData['order_id'] = $data->id;
        //    $newData['children_sn1'] = 'Fc'.time().mt_rand(1,99999);
        //    $newData['fheu'] = 1;
        //    (new OrderGoods())->save($newData);
        //});

    }

}